<?php
/*=============================================================================
|| ##################################################################
||	phpFoX Konsort
|| ##################################################################
||	
||	Copyright		: (C) 2005-2007 PHPFOX Limited a Reality Fox Creation
||	Contact			: info@phpfox.com
||
||	- phpFoX and all of its source code and files are protected by Copyright Laws. 
||
||	- The license for phpFoX permits you to install this software on a single domain (.com, .org, .net, etc.). 
||
||	- You may also not remove this copyright screen which shows the copyright information and credits for phpFoX (RealityFOX Creations). 
||
||	- phpFoX Konsort is NOT a FREE software - http://www.phpfox.com/license/
||
|| ##################################################################
=============================================================================*/

/* $File: ./include/modules/Site/classes/PhpFox_ComponentStyleInstall.class.php, $Author:  $ */



/** Component for installing new styles
 * @version $Id: PhpFox_ComponentStyleInstall.class.php 46 2007-12-14 23:12:21Z phpfoxsv $
 * @package module.site
 *   
 */
class PhpFox_Mod_Site_ComponentStyleInstall extends BaseComponent
{
    function process()
    {
        $oReq = &App::getRequest();
        $oTpl = &$this->_oModule->getTemplate();
        $oCssItem = &$this->_oModule->getItem('Css');
        /* @var $oCssItem PhpFox_Mod_Site_ItemCss */
        $oStyleService = &$this->_oModule->getService('Style');
        /* @var $oStyleService PhpFox_Mod_Site_ServiceStyle */
        $oCache = &App::newObject("Cache");
        App::loadClass('file/File');
        $oFile = &new CFile();
        $oSecurityService = &App::getModuleService('Account', 'Security');
        /* @var $oSecurityService PhpFox_Mod_Account_ServiceSecurity */
        if (!$oSecurityService->hasStaffPerm('MENU_css_default'))
        {
            App::gotoUrl('admin.main');
        }

        $sStylePath = App::getParam('style.path');
        if (($oReq->getAction() == 'install') && ($sDir = $oReq->get('dir')))
        {
            $sName = $oReq->get('name');
            if (!$sName)
            {
                $sName = ucfirst($sDir);
            }
            if (!$oStyleService->styleExists($sName, $sDir) && file_exists($sStylePath.$sDir))
            {
                $oCssItem->aData['name'] = $sName;
                $oCssItem->aData['file'] = $sDir;
                $oCssItem->aData['html'] = '1';
                $oCssItem->insert();
                $oCache->rmFile("css.php");
                App::gotoUrl('admin.config.style-install', array(), App::format('Mod_Site.info.theme_installed'), false, 'install');
            }
            App::gotoUrl('admin.config.style-install');
        }
        $aStyleNames = $oStyleService->getStyleNames();
        $aDirs = $oFile->readDir($sStylePath);
        $aNewStyles = array();
        foreach ($aDirs as $sDir => $bIsDir)
        {
            if ((!$bIsDir) || in_array($sDir, $aStyleNames))
            {
                continue;
            }
            if (file_exists($sStylePath.$sDir.'/style.css'))
            {
                $aNewStyles[] = $sDir;
            }
        }
        $oTpl->assign(array(
            'aItems' => $aNewStyles,
            'iCnt'   => count($aNewStyles),
        ));
        return $oTpl->fetch('StyleInstall.html');
    }
}
?>